﻿using Aspose.Cells;
using System.Data;
using System;

namespace TeacherHelp.Util
{
    public class ExeclTool
    {
        private Workbook _workbook;

        public ExeclTool()
        {
            License license = new License();
            license.SetLicense("License.lic");//注册
        }

        public ExeclTool(string path) : this()
        {
            _workbook = new Workbook();
            try
            {
                _workbook.Open(path);
            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }

        public DataTable getFirstDataTable()
        {
            try
            {
                Cells cells = _workbook.Worksheets[0].Cells;
                var table = cells.ExportDataTable(1, 0, cells.MaxDataRow, cells.MaxColumn + 1, true);
                return table;
            }
            catch (Exception ex)
            {
                throw new Exception($"getFirstDataTable 出现异常 {ex.Message}");
            }
        }

        public DataTable getFirstDataTable(string path)
        {
            _workbook = new Workbook();
            _workbook.Open(path);
            return getFirstDataTable();
        }
    }
}
